package com.yswy.app.res;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.codec.binary.Base64;

import java.util.HashMap;
import java.util.Map;

public class TestLinkUtil {

//    private static final String PUBLIC_KEY = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC85L/PgnMuNIHI4lplrZBQRiVSv0U47k5rkkWe0FdLSSuM2RbY3YoSkF7o7QvvocKYf7DmiGneS3OqbZ2+8j4RY0AL1PF+GRBM6P0S+BS0yyQN1eBgn6bGMJsTytRCijhMU/MsHO4U0/jPfFVAeInhit0kWoV3ju2Cusn/JxbqrwIDAQAB";
//    private static final String PRIVATE_KEY = "MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBALzkv8+Ccy40gcjiWmWtkFBGJVK/RTjuTmuSRZ7QV0tJK4zZFtjdihKQXujtC++hwph/sOaIad5Lc6ptnb7yPhFjQAvU8X4ZEEzo/RL4FLTLJA3V4GCfpsYwmxPK1EKKOExT8ywc7hTT+M98VUB4ieGK3SRahXeO7YK6yf8nFuqvAgMBAAECgYEArtQFV9lEI8LDUJt30V3oEPQrfT+8oOmnuVZji48HDI5HeZA/3i6FqZLn1Sv4/Sy5gA3HPEeLvQwWnOnhs6ZfnHxRwlXpxvb6b0dhb2mNpQ7iGs6RuhlqXfIIpRurUzHBjLlVIm8PkApRmjfWeKoocAcF3GUEl1WLGW3CKNizPzkCQQD3oO+Jy+nqWwqGphwgjamfUM3DqVrEC6NWysehXE7GyDpC6Iih/W20xWW6isNbxd0NHFQjct/LFuO4mzEFKjXLAkEAw0d/5cm1YsLsjsuBJFf+5ERIo9ogvdQoOu+7GGL10ppab2ctXrsF6etLxNF/LGs+Zv85QAL4sPvYe7ZmzcOiLQJBAOJvb5r5s/RxO7bUvnOmFq1wHjgE7NLIMZxz4QhUeFSdU2lLaWV3cJIUz2k86ldJH1GVzfp8WNhFHgb5ImIurvECQDvGfir7xI83tau8NYrHeNms4UNuuMkC0VHBIldDq5XM89PYFHZD73p8MRRNQI17Qn3KsF6cyj16yfiMjAl+Uf0CQQDtIPuNxGLKQ1c1HFDiuVUrkG0N3LSTxI66m+rCCFsZBC3d6loR1IB03WRhFExcbEuWuU98wg07RXzy03SyOWgz";


    private static final String PUBLIC_KEY = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC7bPKLSwYMT5GmAXFbzGo3lYNeVsQQn6+3ulgXFKM0ZHeeUlaymf0PoxvBj32j0h8oVr8xNSvwZGJTF97Pe6fOzZG4lUE3iN8EakZoPmkY3PGtckEFsPcg960Ier4JynHg5OMEE5/Zm5FIhJ8gb37aU/NdxienOPkoDOO2prqQ+wIDAQAB";
    private static final String PRIVATE_KEY = "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBALts8otLBgxPkaYBcVvMajeVg15WxBCfr7e6WBcUozRkd55SVrKZ/Q+jG8GPfaPSHyhWvzE1K/BkYlMX3s97p87NkbiVQTeI3wRqRmg+aRjc8a1yQQWw9yD3rQh6vgnKceDk4wQTn9mbkUiEnyBvftpT813GJ6c4+SgM47amupD7AgMBAAECgYAlDhQh3/JRKsYT+QMNcCur056GX0ciNkAKZggWgBkIObjAj2zeoL08gzXwncrsQZWxZv0j4GxQebhKz1RY1wzE6owumTADN8m4J5E8HWcFH7rW4AATpCgkmaOnutU3PF1gBVAqKyQFSENoJ8+RjdchKgbOyDFBYF0IIq9PnQsgsQJBAOJvkUkpf5pgiooTK1LT9EEValMJG5aah3mpMc6mB6rJ+j7evC6HZgodDBmC00i0jk8okl2MUjA6om8JBPQMqnkCQQDT5X6eaSbLuMg1kLe9s+AiO6Pl7BJna70enrYpR4YsIXFGP2fvkDbJuuGRgVCpCfnN07B1jBuG8rY53ydJ3roTAkBztREnsqX67BQ/JDaCN77btybC0aegWMyblaLW9y55zoYqtESy/gtdZaR2MMzonSMPPis01Gx3Kq8wUAqQ7xv5AkEAyM9Iu58zIQWw1vKa7rC0zDxxCsg6eMBlrcsDHwOlZ9UZoFUejq3A/lSYyGggpNHLZwAizoNE4xLJFvcgKKVm+QJBANi7+VNWOci2wLfgV42gQZCUEnJzA5PabmZuq6wIdGO5bn/4ehMWYD+65O3Y7lDcfmWGu1B4m9GQsL/x9mHp5ho=";

    public static void main(String[] args) {
//        try {
//            Map<String, Object> keyPair = RSAUtils.genKeyPair();
//            System.out.println(JSON.toJSONString(keyPair));
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        String encrypted1 = RSAUtils.encryptedDataOnJavaByPrivateKey(
//                "12345678", PRIVATE_KEY);
//        System.out.println("私钥加密："+encrypted1);
//        String decrypt1 = RSAUtils.decryptDataOnJavaByPublicKey(
//                "JnMgJimMn9NQRDvaoHtkUV4n7J/iawJY0PUXNmIENlEj3Sqkb4f6pwcjRuGX+bPP095M4jHyUwMS\n" +
//                        "jmewsMTO4fkzHmClIecEUOSJCze9151onbM6Gr0SAf4auudST5TumQBKLW/wsn4z5AyNY8GCcJzn\n" +
//                        "OazytUGKM/erVMIIFyY=", PUBLIC_KEY);
//        System.out.println("公钥解密："+decrypt1);
//
//
//
//        String encrypted2 = RSAUtils.encryptedDataOnJava(
//                "123456", PUBLIC_KEY);
//        System.out.println("公钥加密："+encrypted2);
//        String decrypt2 = RSAUtils.decryptDataOnJava(
//                "Wn5PWdykuuh8ECZLhQjxwab/sCWVW/PV1zVGYWmGWgAQQ6EFHPpd1fkn1gBHAzr5dxP5CdXdkhW8\n" +
//                        "j7JY/ksUIqDqyCrutrwT6z3mYXPzzbwuqgIgBx2Id0QQPRoyZceClFqH6paQn3qyyABuGgCv0h3m\n" +
//                        "yxXOjkqWvio2BzKfmGs=", PRIVATE_KEY);
//        System.out.println("私钥解密："+decrypt2);

//        byte[] rs = Base64.decodeBase64("nO2ch9A7coqjIEDashPgT/bB6ot+QkLjCZbmsW4VTkk/46B6hPDBI42wnKMFKH4JeQrilbUIz8Fk");
//        System.out.println(rs);
//        String encodeBase64 = Base64.encodeBase64String(rs);
//        System.out.println(encodeBase64);


//        String aseKey2 = RSAUtils.decryptDataOnJavaByPublicKey(encrypted1, PUBLIC_KEY);
//        System.out.println(aseKey2);


        dadas();

    }

    private static  void dadas(){
        String result = "{" +
                "  \"episodes\": 1," +
                "  \"playId\": \"365\"," +
                "  \"playType\": 1" +
                "}";
        //生成Ase加密字符串
        String aseKey = "x5io9liazcffm56m";

//        String encrypted1 = RSAUtils.encryptedDataOnJavaByPrivateKey(aseKey, PRIVATE_KEY);
//        System.out.println(encrypted1);
//        String aseKey2 = RSAUtils.decryptDataOnJavaByPublicKey(encrypted1, PUBLIC_KEY);
//        System.out.println(aseKey2);
        //用rsa非对称加密Ase加密
        String encrypted = RSAUtils.encryptedDataOnJava(aseKey, PUBLIC_KEY);
        //加密请求参数
        String requestData = null;
        try {
            requestData = AesEncryptUtils.encrypt(result, aseKey);
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println(requestData);
        System.out.println(encrypted);

        Map<String, String> map = new HashMap();
        //加密 Ase加密字符串
        map.put("encrypted", encrypted);
        //加密 请求参数
        map.put("requestData", requestData);
        System.out.println(JSONObject.toJSONString(map));
        System.out.println(JSON.toJSONString(map));
        System.out.println("//-----------------------");
        try {
            //解密Ase加密字符串
            aseKey = RSAUtils.decryptDataOnJava(encrypted, PRIVATE_KEY);
        } catch (Exception var9) {
            throw new RuntimeException("参数【aseKey】解析异常！");
        }
        //解密 请求参数
        try {
            requestData = AesEncryptUtils.decrypt(requestData, aseKey);
        } catch (Exception var8) {
            throw new RuntimeException("参数【content】解析异常！");
        }
        System.out.println(aseKey);
        System.out.println(requestData);
    }

}
